package StringStudy;

import java.util.Scanner;

/*
    检验一个字符串Email是否合法
      1.检验是否包含@
      2.@前边要有字符
      3.@后边要有字符
      4.@后边要包含点
      全部满足，提示用户:Email合法，否则，提示用户非法Eamil
     */
public class StringExample {
    public static void main(String[] args) {
        String email;
        System.out.println("请输入您的eamil:");
        Scanner scanner = new Scanner(System.in);
        email = scanner.next();
        //判断@
        if (email.indexOf("@") == -1) {
            System.out.println("非法email,未包含@");
            return;
        }
        //判断@前面的字符
        if (email.substring(0, email.indexOf("@")).length() == 0) {
            System.out.println("非法email,@前边没有东西");
            return;
        }
        //判断后面的字符
        if (email.substring(email.indexOf("@") + 1, email.length()).length() == 0) {
            System.out.println("非法email,@后边没有东西");
            return;
        }
        //判断后面的点
        if (email.substring(email.indexOf("@") + 1, email.length()).indexOf(".") == -1) {
            System.out.println("非法email,@后边没有.");
            return;
        }
        System.out.println("email合法");
    }
}


